//
//  YFJourneyModel.m
//  project
//
//  Created by yefei on 2019/4/15.
//  Copyright © 2019 健健. All rights reserved.
//

#import "YFJourneyModel.h"

@implementation YFUserTagModel

- (NSString *)description {
    return [self yy_modelDescription];
}

@end

@implementation YFCityModel

- (NSString *)description {
    return [self yy_modelDescription];
}

@end


@implementation YFUserModel

+ (nullable NSDictionary<NSString *, id> *)modelCustomPropertyMapper {
    
    return @{
             @"cityModel":@"city",
             @"tagModels":@"tags",
             };
}

+ (nullable NSDictionary<NSString *, id> *)modelContainerPropertyGenericClass {
    return @{
             @"tagModels": [YFUserTagModel class]
             };
}

- (NSString *)description {
    return [self yy_modelDescription];
}

- (BOOL)modelCustomTransformFromDictionary:(NSDictionary *)dic {
    
    [self transformProperties];
    
    return YES;
}

#pragma mark - 加工数据
- (void)transformProperties {
    
    // 头像 url
    self.avatarURL = [NSURL URLWithString:self.avatar];
    
    // 性别 Image
    NSString *sexImageName = self.sex.integerValue == 1 ? @"ico_mine_male" : @"ico_mine_female";
    self.sexImage = [UIImage imageNamed:sexImageName];
    
    // 年龄字符串
    self.ageString = [self.age stringByAppendingString:@"岁"];
    
    // 用户标签数组 与 标签颜色数组
    NSMutableArray *tagArray = [NSMutableArray arrayWithCapacity:self.tagModels.count];
    NSMutableArray *tagColorArray = [NSMutableArray arrayWithCapacity:self.tagModels.count];
    
    for (YFUserTagModel *tagModel in self.tagModels) {
        [tagArray addObject:tagModel.name];
        
        [tagColorArray addObject:[UIColor withHexString:@"#000000"]];
    }
    
    self.tagArray = [tagArray mutableCopy];
    self.tagColorArray = [tagColorArray mutableCopy];
}


@end

@implementation YFTripModel

- (BOOL)modelCustomTransformFromDictionary:(NSDictionary *)dic {
    
    [self transformProperties];
    
    return YES;
}

+ (nullable NSDictionary<NSString *, id> *)modelCustomPropertyMapper {
    
    return @{
             @"journey_id":@"id",
             };
}

- (NSString *)description {
    return [self yy_modelDescription];
}

#pragma mark - 加工数据
- (void)transformProperties {
    
    // 出行方式 icon 名字
    switch (self.wayId) {
        case 1: // 公交
            self.wayImage = [UIImage imageNamed:@"by_bus"];
            break;
        case 2: // 打车
            self.wayImage = [UIImage imageNamed:@"by_taxi"];
            break;
        case 3: // 火车
            self.wayImage = [UIImage imageNamed:@"by_train"];
            break;
        case 4: // 飞机
            self.wayImage = [UIImage imageNamed:@"by_plane"];
            break;
        case 5: // 散步
            self.wayImage = [UIImage imageNamed:@"by_walk"];
            break;
        default:
            break;
    }
    
    // 创建日期
    
    if (self.createTime && self.createTime.length > 10) {
        self.createTime = [_createTime substringToIndex:10];
    }
    
    if (_beginDate && _endDate ) {
        // 行程日期
        self.journeyDate = [NSString stringWithFormat:@"%@至%@", _beginDate, _endDate];
    }
    
    if (_beginTime && _endTime) {
        // 行程时间
        self.journeyTime = [NSString stringWithFormat:@"%@-%@", _beginTime, _endTime];
    }
}

@end

@implementation YFRecordModel

+ (nullable NSDictionary<NSString *, id> *)modelCustomPropertyMapper {
    
    return @{
             @"tripModel":@"trip",
             @"userModel":@"user",
             };
}
+ (nullable NSDictionary<NSString *, id> *)modelContainerPropertyGenericClass {
    return @{
             @"userList": [HJUserListModel class]
             };
}
- (NSString *)description {
    return [self yy_modelDescription];
}

@end

@implementation YFJourneyModel

+ (nullable NSDictionary<NSString *, id> *)modelContainerPropertyGenericClass {
    return @{
             @"records": [YFRecordModel class]
             };
}

- (NSString *)description {
    return [self yy_modelDescription];
}

@end

@implementation HJUserListTripModel

+ (nullable NSDictionary<NSString *, id> *)modelCustomPropertyMapper {
    return @{@"like_id":@"id" };
}
- (NSString *)description {
    return [self yy_modelDescription];
}
@end



@implementation HJUserListModel

+ (nullable NSDictionary<NSString *, id> *)modelContainerPropertyGenericClass {
    return @{
             @"user": [YFUserModel class],@"trip":[HJUserListTripModel class]
             };
}

- (NSString *)description {
    return [self yy_modelDescription];
}
@end
